﻿using Microsoft.AspNetCore.Builder;
using YiShop.Framework.Extensions;

namespace YiShop.Framework
{
    public static class AppApplicationBuilderExtensions
    {
        /// <summary>
        /// 注入基础中间件（带Swagger）
        /// </summary>
        /// <param name="app"></param>
        /// <param name="routePrefix">空字符串将为首页</param>
        /// <param name="configure"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseInject(this IApplicationBuilder app)
        {
            App.RootServices = app.ApplicationServices;
            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "V1版本");
            });
            app.UseCors();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHubsByAttribute(); // 自动注册所有标记了 [HubRoute] 的 Hub

            });
            return app;
        }
    }
}
